#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

import sys
import os

parent = os.path.abspath(sys.argv[1])
worknumber = parent.split("_")[-1]
infile = open("pmc_pdf_worklist_" + worknumber + ".list", "r")
idlist = {}
for line in infile:
    line = line.rstrip()
    idlist[line] = 0
infile.close()
list = os.listdir(parent)
for file in list:
    if os.path.isfile(parent + "/" + file) and file[-3:] == "pdf":
        id = file[3:-4]
        del idlist[id]

outfile = open("pmc_pdf_worklist_missing" + worknumber + ".list", "w")
if len(idlist) != 0:
    for item in idlist.keys():
        outfile.write(item + "\n")
        outfile.flush()
outfile.close()